#pragma once

#include "d3d9.h"
#include "d3dx9.h"
#include <vector>
#include "ModelManager.h"
#include "ObstacleManager.h"
#include "TimerBar.h"
#include "Camera.h"

// Add pragma comments so we do not have to change
// the project dependencies
#pragma comment (lib, "d3d9.lib")
#pragma comment (lib, "d3dx9.lib")

struct s_Mines
{
	D3DXMATRIX			worldMat, scaleMat, rotMat, transMat;
	D3DXVECTOR3			vecPos;
	bool				bActive;
	// AABB members
	D3DXVECTOR3			vecBBMin;
	D3DXVECTOR3			vecBBMax;
	D3DXVECTOR3			vecModelBounds[8];
	D3DXVECTOR3			worldBBmin;
	D3DXVECTOR3			worldBBmax;
	// AABB members (SECOND SET)
	D3DXVECTOR3			vecMagBBMin;
	D3DXVECTOR3			vecMagBBMax;
	D3DXVECTOR3			vecMagModelBounds[8];
	D3DXVECTOR3			worldMagBBmin;
	D3DXVECTOR3			worldMagBBmax;
};

class VirusEnemy
{
private:
	// Singleton instance
	static VirusEnemy*	m_VirusEnInstance;
	// Pointer to the D3D Device
	IDirect3DDevice9*	m_Device;
	// Pointers
	ModelManager*		m_ModelMan;
	TimerBar*			m_pTimerBar;
	Camera*				m_pCam;
	///////////////////////////////////////////////////
	//MINE VARIABLES
	// X object variables
	ID3DXMesh*			m_pMineMesh;
	D3DMATERIAL9*		m_pMaterials;
	DWORD				m_dwNumMaterials;
	LPDIRECT3DTEXTURE9*	m_pMeshTextures;
	// Mesh that keeps track of how big the sensor around the spawner
	ID3DXMesh*			m_SensorMesh;
	// Create the vector list to hold the spawners
	std::vector<s_Mines*>	mineList;
	// Count to keep track of the number of spawners
	short				sMineCount;
	///////////////////////////////////////////////////
	// Mesh for the bounding box
	ID3DXMesh*			m_BBMesh;
	// Vector to hold the distance for pull effect
	D3DXVECTOR3			vecDistance;
	float				fSpeed;
	float				fZModelPos;
	// Boundaries of where they can be created
	short				sXMax;
	short				sXMin;

public:
	VirusEnemy(void);
	~VirusEnemy(void);
	
	bool				bExplosion;

	// Singleton functions
	static VirusEnemy*	GetInstance(void);
	void DeleteVirusInstance(void);
	// Init Virus function
	void InitMines(IDirect3DDevice9* m_pD3DDevice);
	// Create, Update & Render functions
	void CreateMines(short sEnSpawnerCount);
	void UpdateMines(float deltaTime);
	void StartPull(short iVirusID, float fDeltaTime);
	void RenderMines(void);
	void ReactivateMines(void);
	// Collision functions
	void CalculateWorldBB(short sMineID);
	void CalculateSensorWorldBB(short sMineID);
	bool CollisionDetection(short sMineID);
	bool SensorCollisionDetection(short sMineID);
	// Shutdown function
	void ClearMineList(void);
	void ShutdownMines(void);
};
